'use strict'

const { DataTypes, Model, Op } = require('../../../azeroth').sequelize;
class Panel_info_1 extends Model { }

const initPanelInfoData_1 = (sequelize_aim) => {
  Panel_info_1.init(
    {
      uid: {
        autoIncrement: true,
        type: DataTypes.INTEGER,
        allowNull: false,
        primaryKey: true
      },
      doff_id: {
        type: DataTypes.INTEGER,
        allowNull: true
      },
      create_time: {
        type: DataTypes.BIGINT,
        allowNull: true
      },
      panel_id: {
        type: DataTypes.STRING(40),
        allowNull: true
      },
      lot_id: {
        type: DataTypes.STRING(40),
        allowNull: true
      },
      meter: {
        type: DataTypes.INTEGER,
        allowNull: true
      },
      ex_info1: {
        type: DataTypes.TEXT,
        allowNull: true
      },
      ex_info2: {
        type: DataTypes.TEXT,
        allowNull: true
      },
      ex_info3: {
        type: DataTypes.TEXT,
        allowNull: true
      },
      ex_info4: {
        type: DataTypes.TEXT,
        allowNull: true
      },
      ex_info5: {
        type: DataTypes.TEXT,
        allowNull: true
      }
    },
    {
      freezeTableName: true,
      sequelize: sequelize_aim,
      modelName: 'panel_info',
      timestamps: false
    }
  )
}

Panel_info_1.getMaxUid = async (sequelize_aim) => {
  let res = await sequelize_aim.query(`select max(uid) as uid from panel_info`, { type: sequelize_aim.QueryTypes.SELECT });
  if (res.length) {
    return res[0].uid;
  } else {
    return 0;
  }
}

Panel_info_1.upload = async (data) => {
  let res = await Panel_info_1.bulkCreate([data], {
    updateOnDuplicate: ['uid', 'doff_id', 'create_time', 'panel_id', 'lot_id', 'meter', 'ex_info1', 'ex_info2']
  });
  return res;
}

module.exports = {
  Panel_info_1,
  initPanelInfoData_1
};